var iDiffX = 0;
var iDiffY = 0;
var dragDiv = null;
var curDiv;

/**
 * 鼠标按下时的事件函数
 */
 var left = 0;
 var top = 0;

function handleMouseDown(eventDiv,event){
    var oEvent = EventUtil.getEvent(event);
    dragDiv = eventDiv;   
    if(dragDiv.setCapture){
    	 dragDiv.setCapture();
    }
    else if(window.captureEvents){
    	window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);	
    }
    iDiffX = oEvent.clientX - dragDiv.offsetLeft;
    iDiffY = oEvent.clientY - dragDiv.offsetTop;
    EventUtil.addEventHandler(document.body, "mousemove", handleMouseMove);
    EventUtil.addEventHandler(document.body, "mouseup", handleMouseUp);
	if(curDiv!=eventDiv){
	  if(curDiv)
	  curDiv.style.zIndex='20';
	  eventDiv.style.zIndex='99';
	 }
	 curDiv=eventDiv;
}

function handleMouseUp(){
	if(dragDiv.releaseCapture)
    		dragDiv.releaseCapture();
   	else if(window.captureEvents)
    		window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
     
    EventUtil.removeEventHandler(document.body, "mousemove", handleMouseMove);
    EventUtil.removeEventHandler(document.body, "mouseup", handleMouseUp);    
	dragDiv = null;
	iDiffX = 0;
	iDiffY = 0;
}
function handleMouseMove(event){
    var oEvent = EventUtil.getEvent(event);
    dragDiv.style.left = (oEvent.clientX - iDiffX)+"px";
    dragDiv.style.top = (oEvent.clientY - iDiffY)+"px";
}